/**
*   FuzzyEngine - an Simple flex framework 
*   Copyright (C) 2010 Constantin Aldea
*
*   This program is free software: you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation, either version 3 of the License, or
*   (at your option) any later version.
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   You should have received a copy of the GNU General Public License
*   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package main.com.sibilla.model {
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.utils.Dictionary;
	
	import main.com.sibilla.events.ServiceInitializeEvent;
	import main.com.sibilla.interfaces.IContext;

	public class AbstractContext extends EventDispatcher implements IContext
	{
		
		protected var _debug:Boolean;
	
		
		public function AbstractContext(target:IEventDispatcher=null)
		{
			super(target);
			
		}
		
		public function getInstance():IContext{
			return null;
		}
	
		protected  function initialize_service():void{
		 	this.dispatchEvent(this.registerConnector(new Connector(Connector.LOCAL)));
		}

		
		

/**
* @description  usato per registrare un nuovo connector (default e gia previsto con 3 tipi di connector: LOCAL, PREPROD, PRODUCTION
* @param  val FuzzyConnector
* @return  ServiceInitializeEvent
* @see initialize_service
*/
	
		public  function  registerConnector(val:Connector):ServiceInitializeEvent{
			if(val != null){
				connector = val;
				return new ServiceInitializeEvent();
			}
			return null;
		}

		///////////////////////////////////
		//     PUBLIC/PROTECTED PROPERTIES
		////////////////////////////////////
		
		/*
		* property-name: url_Fuzzy
		* scope: protected
		* note: e una stringa che la classe httpservice usera per connettersi 
		*/
		protected var _url_Fuzzy:String;
		public function get url_Fuzzy ():String
		{
			
			if(_connector == null){
				this.initialize_service();
			}
			return _connector.url_Fuzzy;
		}
		
		/*
		* property-name: connector
		* scope: protected
		* note:  usato per creare registrare un connector (connector e un device che crea l'url di connessione
		*/
		
		protected var _connector:Connector;
		[Bindable(event="connectorChange")]
		public  function set connector (value:Connector):void
		{
			if (value != _connector)
			{
				_connector = value;
				dispatchEvent (new Event ("connectorChange"));
			}
		}

		public  function get connector ():Connector
		{
			return _connector;
		}
		 
		private var _widgets:Dictionary;

		
		public function getWidget():Dictionary
		{
			return _widgets;
		}
		
		public function get debug() : Boolean {
			// TODO: Auto-generated method stub
			return _debug;
		}

		

		public function set debug(val : Boolean) : void {
			_debug = val;
		}

		
	}
}